package 力扣;

import java.util.Stack;

/**
 * @author yyq
 * @create 2022-03-30 19:06
 */
public class leetcode150 {
    public static void main(String[] args) {
        evalRPN(new String[]{"10","6","9","3","+","-11","*","/","*","17","+","5","+"});
    }
    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {

            if(tokens[i].equals("+")){
                Integer one = stack.pop();
                Integer two = stack.pop();
                stack.push(one+two);
            }else if (tokens[i].equals("-")){
                Integer one = stack.pop();
                Integer two = stack.pop();
                stack.push(two-one);
            }else if(tokens[i].equals("*")){
                Integer one = stack.pop();
                Integer two = stack.pop();
                stack.push(one*two);
            }
            else if (tokens[i].equals("/")){
                Integer one = stack.pop();
                Integer two = stack.pop();
                stack.push(two/one);
            }
            else {
                stack.push(new Integer(tokens[i]));
            }
        }
        return stack.pop();

    }
}
